from datetime import timedelta
from utils.operators.cluster_for_spark_sql_operator import SparkSqlOperator
from jms_hi.dwd.dwd_wide_tms_road_waybill_hf import jms_dwd__dwd_wide_tms_road_waybill_hf
from jms_hi.dim.dim_network_whole_massage import jms_dim__dim_network_whole_massage
from jms_hi.dim.dim_tmsnew_vehicle_line import jms_dim__dim_tmsnew_vehicle_line
from jms_hi.dim.dim_tab_mainline_nuclear_load_dt import jms_dim__dim_tab_mainline_nuclear_load_dt

jms_dm__dm_tms_shipment_line_load_rate_ht = SparkSqlOperator(
    task_id='jms_dm__dm_tms_shipment_line_load_rate_ht',
    task_concurrency=1,
    # pool_slots=4,
    master='yarn',
    execution_timeout=timedelta(hours=3),
    email=['matthew.xiong@jtexpress.com','yl_bigdata@yl-scm.com'],
    name='jms_dm__dm_tms_shipment_line_load_rate_ht_{{ execution_date | cst_ds }}',
    sql='jms_hi/dm/dm_tms_shipment_line_load_rate_ht/execute.sql',
    driver_memory='6G',
    executor_memory='8G',
    driver_cores=2,
    executor_cores=5,
    num_executors=3,
    conf={'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
          'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
          'spark.dynamicAllocation.maxExecutors'             : 5,
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 180,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          'spark.sql.sources.partitionOverwriteMode': 'dynamic',  # 允许删改已存在的分区
          'spark.sql.shuffle.partitions': 100,
          'spark.default.paralleism': 100,
          'spark.hadoop.hive.exec.dynamic.partition.mode': 'true',
          'spark.network.timeout': 900,
          'spark.core.connection.ack.wait.timeout': 300,
          'spark.executor.memoryOverhead': '4G',  # 堆外内
          },
    hiveconf={'hive.exec.dynamic.partition': 'true',  # 动态分区
              'hive.exec.dynamic.partition.mode': 'nonstrict',
              'hive.exec.max.dynamic.partitions': 200,  # 每天生成 20 个分区
              'hive.exec.max.dynamic.partitions.pernode': 200,  # 每天生成 20 个分区
              },
    yarn_queue='pro',
)


jms_dm__dm_tms_shipment_line_load_rate_ht << [
    jms_dwd__dwd_wide_tms_road_waybill_hf,
    jms_dim__dim_network_whole_massage,
    jms_dim__dim_tmsnew_vehicle_line,
    jms_dim__dim_tab_mainline_nuclear_load_dt
]
